package com.app.hanoitips.travel;




import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;


public class MainMenu extends Activity implements View.OnClickListener{
    
	Button btRest,btCafe,btTea,btUtil,btSetting,btVnFood;
	Intent openSubMenu;
	TextView tv;
	SharedPreferences sp;
	private int choice;
	private String title,btDialogOK;
	private CharSequence[] lang;
	private CharSequence[] eg={"English","Vietnamese","Japanese"};
	private CharSequence[] vn={"Tiếng Anh","Tiếng Việt","Tiếng Nhật"};
	private CharSequence[] jp={"英語","ベトナム語","日本語"};
	@Override
	protected void onCreate(Bundle menuInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(menuInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);// Removes title bar
		setContentView(R.layout.main_menu);
		btRest=(Button) findViewById(R.id.btRestaurant);
		btCafe=(Button) findViewById(R.id.btCafe);
		btTea=(Button) findViewById(R.id.btTea);
		
	    btUtil=(Button) findViewById(R.id.btUtil);
	    btSetting=(Button) findViewById(R.id.btSetting);
	    btVnFood=(Button) findViewById(R.id.btVNFood);
	    
		btRest.setOnClickListener(this);
		btCafe.setOnClickListener(this);
		btTea.setOnClickListener(this);
		btUtil.setOnClickListener(this);
		btSetting.setOnClickListener(this);
		btVnFood.setOnClickListener(this);
		
		sp=PreferenceManager.getDefaultSharedPreferences(this);
		choice=sp.getInt("keyLang", 0);
		
		if(choice==0){
			title="Choose Language";
			lang=eg;
			btRest.setText("Restaurants");
			btCafe.setText("Cafe");
			btTea.setText("Tea");
			btUtil.setText("Util");
			btSetting.setText("Setting");
			btVnFood.setText("VN-Foods");
			btDialogOK="Accept";
		} else if(choice==1){
			title="Chọn Ngôn Ngữ";
			lang=vn;
			btRest.setText("Quán Ăn");
			btCafe.setText("Cafe");
			btTea.setText("Trà");
			btUtil.setText("Hỗ Trợ");
			btSetting.setText("Cài Đặt");
			btVnFood.setText("Món Việt");
			btDialogOK="Chấp Nhận";
		}else{
			title="言語を選択します";
			lang=jp;
			btRest.setText("レストラン");
			btCafe.setText("カフェ");
			btTea.setText("お茶");
			btUtil.setText("Hỗ Trợ");
			btSetting.setText("設定");
			btVnFood.setText("設定");
			btDialogOK="OK";
		}
		
	}
	
		
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.btRestaurant:
			openSubMenu=new Intent("android.intent.action.CustomizedListView");
			Bundle rExtra=new Bundle();
			rExtra.putString("key", "vnRestaurants");
			openSubMenu.putExtras(rExtra);
			startActivity(openSubMenu);
			// behavior of the new activity window appear
			overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
			break;
		case R.id.btCafe:
			openSubMenu=new Intent("android.intent.action.CustomizedListView");
			Bundle cExtra=new Bundle();
			cExtra.putString("key", "vnCafes");
			openSubMenu.putExtras(cExtra);
			startActivity(openSubMenu);
			break;
		case R.id.btTea:
			openSubMenu=new Intent("android.intent.action.CustomizedListView");
			Bundle tExtra=new Bundle();
			tExtra.putString("key", "teas");
			openSubMenu.putExtras(tExtra);
			startActivity(openSubMenu);
			break;
		case R.id.btUtil:
			openSubMenu=new Intent("android.intent.action.ShowUtils");
			Bundle utilExtra=new Bundle();
			utilExtra.putString("key", "utils");
			startActivity(openSubMenu);
			break;
		case R.id.btSetting:
			AlertDialog.Builder builder=new AlertDialog.Builder(this);
			builder.setTitle(title);
			builder.setSingleChoiceItems(lang, choice, new DialogInterface.OnClickListener() {								@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					//choice=which;
					sp=PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
					Editor editor=sp.edit();
					editor.putInt("keyLang", which);
					editor.commit();
					}
			});
			builder.setPositiveButton(btDialogOK, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					Intent menu=new Intent("android.intent.action.MainMenu");
					startActivity(menu);
				}
			});

			AlertDialog langOptions=builder.create();
			langOptions.show();
			break;
		}
	}

}
